﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using DbUtility;
using MvcPager;

namespace Models
{
    #region 实体模型
    public partial class admin_account : INotifyPropertyChanged
    {

        /// <summary>
        /// 属性更改通知
        /// </summary>
        private List<string> _ChangedList = new List<string>();
        /// <summary>
        /// 属性更改通知
        /// </summary>
        [ColumnAttribute("ChangedList", true, false, true)]
        public List<string> ChangedList { get { return _ChangedList; } }
        /// <summary>
        /// 客户端通知事件
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged(string propName)
        {
            if (_ChangedList == null || !_ChangedList.Contains(propName))
            {
                _ChangedList.Add(propName);

            }
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propName));

            }
        }
        /// <summary>
        ///id
        /// </summary>
        private Int32 _id;
        /// <summary>
        ///id
        /// </summary>
        [ColumnAttribute("id", false, true, false)]
        public Int32 id { get { return _id; } set { _id = value; OnPropertyChanged("id"); } }


        /// <summary>
        ///username
        /// </summary>
        private String _username;
        /// <summary>
        ///username
        /// </summary>
        [ColumnAttribute("username", false, false, false)]
        public String username { get { return _username; } set { _username = value; OnPropertyChanged("username"); } }


        /// <summary>
        ///usertype
        /// </summary>
        private Int32 _usertype;
        /// <summary>
        ///usertype
        /// </summary>
        [ColumnAttribute("usertype", false, false, false)]
        public Int32 usertype { get { return _usertype; } set { _usertype = value; OnPropertyChanged("usertype"); } }


        /// <summary>
        ///name
        /// </summary>
        private String _name;
        /// <summary>
        ///name
        /// </summary>
        [ColumnAttribute("name", false, false, true)]
        public String name { get { return _name; } set { _name = value; OnPropertyChanged("name"); } }


        /// <summary>
        ///password
        /// </summary>
        private String _password;
        /// <summary>
        ///password
        /// </summary>
        [ColumnAttribute("password", false, false, false)]
        public String password { get { return _password; } set { _password = value; OnPropertyChanged("password"); } }


        /// <summary>
        ///createdate
        /// </summary>
        private DateTime _createdate;
        /// <summary>
        ///createdate
        /// </summary>
        [ColumnAttribute("createdate", false, false, false)]
        public DateTime createdate { get { return _createdate; } set { _createdate = value; OnPropertyChanged("createdate"); } }


        /// <summary>
        ///modifydate
        /// </summary>
        private DateTime? _modifydate;
        /// <summary>
        ///modifydate
        /// </summary>
        [ColumnAttribute("modifydate", false, false, true)]
        public DateTime? modifydate { get { return _modifydate; } set { _modifydate = value; OnPropertyChanged("modifydate"); } }


        /// <summary>
        ///groupid
        /// </summary>
        private Int32 _groupid;
        /// <summary>
        ///groupid
        /// </summary>
        [ColumnAttribute("groupid", false, false, false)]
        public Int32 groupid { get { return _groupid; } set { _groupid = value; OnPropertyChanged("groupid"); } }


        /// <summary>
        ///isdeleted
        /// </summary>
        private Boolean _isdeleted;
        /// <summary>
        ///isdeleted
        /// </summary>
        [ColumnAttribute("isdeleted", false, false, false)]
        public Boolean isdeleted { get { return _isdeleted; } set { _isdeleted = value; OnPropertyChanged("isdeleted"); } }




    }
    #endregion
    #region 基本业务
    public partial class admin_accountLogic : BaseService
    {

        /// <summary>
        /// 构造函数
        /// </summary>
        public admin_accountLogic()
        {
            db = new DBContext();
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="obj">操作数据库对象</param>
        public admin_accountLogic(DBContext obj)
        {
            db = obj;
        }
        /// <summary>
        /// 添加admin_account
        /// </summary>
        /// <param name="obj">添加对象</param>
        /// <returns>成功True失败False</returns>
        public bool Add(admin_account obj)
        {
            try
            {
                if (obj.id > 0) throw new Exception("数据库已存在此数据");

                string result = base.Add(obj);

                return base.Save(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 添加admin_account
        /// </summary>
        /// <param name="obj">添加对象</param>
        /// <returns>返回id</returns>
        public int Create(admin_account obj)
        {
            try
            {
                if (obj.id > 0) throw new Exception("数据库已存在此数据");
                string result = base.Add(obj);
                base.Save(result);
                return Convert.ToInt32(new DBContext().ExecuteScalarSql("select max(id) from [admin_account]"));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 批量添加
        /// </summary>
        public bool Add(List<admin_account> obj)
        {
            try
            {
                List<string> result = new List<string>();

                foreach (admin_account item in obj)
                {
                    if (item.id == 0)
                    {
                        string sql = base.Add(item);
                        result.Add(sql);
                    }
                }

                return base.Save(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 修改admin_account
        /// </summary>
        /// <param name="obj">修改对象</param>
        /// <returns>成功True失败False</returns>
        public bool Update(admin_account obj)
        {
            try
            {
                if (obj.id == 0) throw new Exception("数据库不存在当前数据");
                string result = base.Update(obj);
                return base.Save(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 批量修改
        /// </summary>
        /// <param name="olts"></param>
        /// <returns></returns>
        public bool Update(List<admin_account> olts)
        {
            try
            {
                string sql = "";
                foreach (var item in olts)
                {
                    sql += base.Update(item) + " ";
                }
                return base.Save(sql);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 根据编号删除admin_account，此处为逻辑删除，实为更新IsDelete字段
        /// </summary>
        /// <param name="id">编号</param>
        /// <returns>成功True失败False</returns>
        public bool Delete(int id)
        {
            try
            {
                string result = base.Update(new admin_account { id = id, isdeleted = true });

                return base.Save(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 删除admin_account，此处为逻辑删除，实为更新IsDelete字段
        /// </summary>
        /// <param name="obj">删除对象</param>
        /// <returns>成功True失败False</returns>
        public bool Delete(admin_account obj)
        {
            string sql = "";
            try
            {
                var olts = base.GetObjects<admin_account>(obj);
                if (olts != null)
                {
                    foreach (var item in olts)
                    {
                        if (item.id > 0)
                        {
                            item.isdeleted = true;
                            sql += base.Update(item) + " ";
                        }
                    }
                    return base.Save(sql);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return false;
        }
        /// <summary>
        /// 删除admin_account集合，此处为逻辑删除，实为更新IsDelete字段
        /// </summary>
        /// <param name="objs">删除对象集合</param>
        /// <returns>成功True失败False</returns>
        public bool Delete(IList<admin_account> objs)
        {
            try
            {
                if (objs == null || objs.Count == 0) return false;

                StringBuilder sql = new StringBuilder();

                foreach (var item in objs)
                {
                    if (item.id > 0)
                    {
                        item.isdeleted = true;

                        string result = base.Update(item) + " ";

                        sql.Append(result);
                    }
                }

                return base.Save(sql.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 根据编号删除admin_account，物理删除
        /// </summary>
        /// <param name="id">编号</param>
        /// <returns>成功True失败False</returns>
        public bool Remove(int id)
        {
            try
            {
                string result = base.Delete(new admin_account { id = id });

                return base.Save(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 根据编号删除admin_account，物理删除
        /// </summary>
        /// <param name="obj">查询条件对象</param>
        /// <returns>成功True失败False</returns>
        public bool Remove(admin_account obj)
        {
            try
            {
                if (obj.id < 1) throw new Exception("数据库不存在当前数据");
                string result = base.Delete(obj);
                return base.Save(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 根据编号删除admin_account，物理删除
        /// </summary>
        /// <param name="obj">查询条件对象</param>
        /// <returns>成功True失败False</returns>
        public bool Remove(IList<admin_account> objs)
        {
            try
            {
                string result = "";
                foreach (var obj in objs)
                {
                    if (obj.id > 0)
                    {
                        result = base.Delete(obj);
                        base.Save(result);
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 获取admin_account集合
        /// </summary>
        /// <returns>返回admin_account集合</returns>
        public List<admin_account> Getadmin_accounts()
        {
            List<admin_account> objs = base.GetObjects<admin_account>(new admin_account() { isdeleted = false });

            return objs;
        }
        /// <summary>
        /// 获取admin_account集合
        /// </summary>
        /// <param name="obj">查询条件</param>
        /// <returns>返回admin_account集合</returns>
        public List<admin_account> Getadmin_accounts(admin_account obj)
        {
            obj.isdeleted = false;

            List<admin_account> objs = base.GetObjects(obj);

            return objs;
        }
        /// <summary>
        /// 获取admin_account集合
        /// </summary>
        /// <param name="obj">查询条件</param>
        /// <param name="where">特殊条件</param>
        /// <returns>返回admin_account集合</returns>
        public List<admin_account> Getadmin_accounts(admin_account obj, string where)
        {
            obj.isdeleted = false;

            List<admin_account> objs = base.GetObjects(obj, where);

            return objs;
        }
        /// <summary>
        /// 获取admin_account集合
        /// </summary>
        /// <param name="obj">查询条件</param>
        /// <param name="where">特殊条件</param>
        ///  <param name="orderby">排序</param>
        /// <returns>返回admin_account集合</returns>
        public List<admin_account> Getadmin_accounts(admin_account obj, string where, string order)
        {
            obj.isdeleted = false;

            List<admin_account> objs = base.GetObjects(obj, where, order, string.Empty);

            return objs;
        }
        /// <summary>
        /// 获取admin_account集合
        /// </summary>
        /// <param name="obj">查询条件</param>
        /// <param name="where">特殊条件</param>
        /// <param name="orderby">排序</param>
        /// <param name="orderbyType">排序类型</param>
        /// <returns>返回admin_account集合</returns>
        public List<admin_account> Getadmin_accounts(admin_account obj, string where, string order, string by)
        {
            obj.isdeleted = false;

            List<admin_account> objs = base.GetObjects(obj, where, order, by);

            return objs;
        }
        /// <summary>
        /// 获取admin_account集合
        /// </summary>
        /// <param name="pageIndex">页数</param>
        /// <param name="pageCount">每页多少条</param>
        /// <returns>返回admin_account集合</returns>
        public Page<admin_account> Getadmin_accounts(int pageIndex, int pageCount)
        {
            Page<admin_account> objs = base.GetObjects(new admin_account() { isdeleted = false }, pageIndex, pageCount);

            return objs;
        }
        /// <summary>
        /// 获取admin_account集合
        /// </summary>
        /// <param name="pageIndex">页数</param>
        /// <param name="pageCount">每页多少条</param>
        /// <param name="obj">查询条件</param>
        /// <returns>返回admin_account集合</returns>
        public Page<admin_account> Getadmin_accounts(admin_account obj, int pageIndex, int pageCount)
        {
            obj.isdeleted = false;

            Page<admin_account> objs = base.GetObjects(obj, pageIndex, pageCount);

            return objs;
        }
        /// <summary>
        /// 获取admin_account集合
        /// </summary>
        /// <param name="pageIndex">页数</param>
        /// <param name="pageCount">每页多少条</param>
        /// <param name="obj">查询条件</param>
        /// <returns>返回admin_account集合</returns>
        public Page<admin_account> Getadmin_accounts(string sql, int pageIndex, int pageCount)
        {
            Page<admin_account> objs = base.GetObjects<admin_account>(sql, pageIndex, pageCount);
            return objs;
        }
        /// <summary>
        /// 获取admin_account集合
        /// </summary>
        /// <param name="pageIndex">页数</param>
        /// <param name="pageCount">每页多少条</param>
        /// <param name="obj">查询条件</param>
        ///  <param name="where">自定义查询条件</param>
        /// <returns>返回admin_account集合</returns>
        public Page<admin_account> Getadmin_accounts(admin_account obj, int pageIndex, int pageCount, string where)
        {
            obj.isdeleted = false;

            Page<admin_account> objs = base.GetObjects(obj, pageIndex, pageCount, where);

            return objs;
        }
        /// <summary>
        /// 获取admin_account集合
        /// </summary>
        /// <param name="pageIndex">页数</param>
        /// <param name="pageCount">每页多少条</param>
        /// <param name="obj">查询条件</param>
        ///  <param name="orderby">排序</param>
        /// <returns>返回admin_account集合</returns>
        public Page<admin_account> Getadmin_accounts(admin_account obj, int pageIndex, int pageCount, string order, string by)
        {
            obj.isdeleted = false;

            Page<admin_account> objs = base.GetObjects(obj, pageIndex, pageCount, string.Empty, order, by);

            return objs;
        }
        /// <summary>
        /// 获取admin_account集合
        /// </summary>
        /// <param name="pageIndex">页数</param>
        /// <param name="pageCount">每页多少条</param>
        /// <param name="obj">查询条件</param>
        ///  <param name="orderby">排序</param>
        /// <returns>返回admin_account集合</returns>
        public Page<admin_account> Getadmin_accounts(admin_account obj, int pageIndex, int pageCount, string where, string order, string by)
        {
            obj.isdeleted = false;

            Page<admin_account> objs = base.GetObjects(obj, pageIndex, pageCount, where, order, by);

            return objs;
        }
        /// <summary>
        /// 获取admin_account
        /// </summary>
        /// <param name="obj">查询条件</param>
        /// <returns>返回admin_account</returns>
        public admin_account Getadmin_account(admin_account obj)
        {
            obj.isdeleted = false;

            admin_account entity = base.GetObject(obj);

            return entity;
        }
        /// <summary>
        /// 根据编号获取admin_account
        /// </summary>
        /// <param name="id">编号</param>
        /// <returns>返回admin_account</returns>
        public admin_account Getadmin_account(int id)
        {
            admin_account entity = base.GetObject(new admin_account { id = id, isdeleted = false });

            return entity;
        }

    }
    #endregion

    #region 基本数据库访问
    internal partial class admin_accountService : BaseService
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public admin_accountService()
        {
            db = new DBContext();
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="obj">操作数据库对象</param>
        public admin_accountService(DBContext obj)
        {
            db = obj;
        }

    }
    #endregion
}